<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="shortcut icon" href="<!--{eval echo register_static('img/touch-icon-57x57.png');}-->">

    <title>粉粉管理系统</title>

    <!-- Bootstrap core CSS -->
    <link href="<!--{eval echo register_static('css/bootstrap.min.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('css/bootstrap-reset.css');}-->" rel="stylesheet">

    <!--Animation css-->
    <link href="<!--{eval echo register_static('css/animate.css');}-->" rel="stylesheet">

    <!--Icon-fonts css-->
    <link href="<!--{eval echo register_static('assets/font-awesome/css/font-awesome.css');}-->" rel="stylesheet" />
    <link href="<!--{eval echo register_static('assets/ionicon/css/ionicons.min.css');}-->" rel="stylesheet" />

    <link href="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.css');}-->" rel="stylesheet">

    <!-- Plugins css -->
    <link href="<!--{eval echo register_static('assets/modal-effect/css/component.css');}-->" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="<!--{eval echo register_static('css/style.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('css/helper.css');}-->" rel="stylesheet">

    <!-- My styles for this template -->
    <link href="<!--{eval echo register_static('css/common.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('css/lightbox.css');}-->" rel="stylesheet">

</head>

<body>

<!-- Aside Start-->
<!--{template admin_v2/leftside}-->
<!-- Aside Ends-->


<!--Main Content Start -->
<section class="content">

    <!-- Header -->
    <!--{template admin_v2/header}-->
    <!-- Header Ends -->


    <!-- Page Content Start -->
    <!-- ================== -->

    <div class="wraper container-fluid attachments">

        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">圈子话题附件列表</h3>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-12 col-sm-12 col-xs-12">
                                <div class="btn-group m-b-10 select-sheet">
                                    <button type="button" href="#" class="btn btn-primary w-xs m-b-5" disabled="disabled">请先选表</button>
                                    <a type="button" href="javascript:void(0);" class="btn btn-default">0</a>
                                    <a type="button" href="javascript:void(0);" class="btn btn-default">1</a>
                                    <a type="button" href="javascript:void(0);" class="btn btn-default">2</a>
                                    <a type="button" href="javascript:void(0);" class="btn btn-default">3</a>
                                    <a type="button" href="javascript:void(0);" class="btn btn-default">4</a>
                                    <a type="button" href="javascript:void(0);" class="btn btn-default">5</a>
                                    <a type="button" href="javascript:void(0);" class="btn btn-default">6</a>
                                    <a type="button" href="javascript:void(0);" class="btn btn-default">7</a>
                                </div>
                                <div id="attachments_list" class="item_list infinite_scroll">
                                    <!--{loop $list $img}-->
                                    <div class="item masonry_brick" data-id="{$img['id']}" data-bodyid="{$img['bodyId']}" data-uid="{$img['uid']}">
                                        <div class="img">
                                            <a href="{$img['attachmentPathOrigin']}" data-lightbox="{$img['attachmentPathOrigin']}"><img alt="图片附件" src="{$img['attachmentPath']}" /></a>
                                            <div>
                                                <span class="uptime"><b>用户： {$img['uid']}</b></span>
                                                <span class="uptime"><i>{$img['uploadTime']}</i></span>
                                            </div>
                                            <div class="btns">
                                                <label class="cr-styled"><input type="checkbox" class="checkone" data-id="{$img['id']}" data-bodyid="{$img['bodyId']}" data-uid="{$img['uid']}"><i class="fa"></i></label>
                                                <a href="javascript:void(0);" class="btn-primary btn-xs delete-attachment">删除</a>
                                            </div>
                                        </div>
                                    </div>
                                    <!--{/loop}-->
                                </div>
                            </div>
                        </div>
                    </div>

                    <div>
                        <button class="btn btn-primary btn-lg m-b-5 delall">删除</button>
                    </div>

                    <div>
                        <nav>
                            <ul class="pager">
                                <li id="nextpage">
                                    <a href="#">下一页</a>
                                </li>
                                <li>
                                    <div class="loading"></div>
                                </li>
                            </ul>
                        </nav>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- Page Content Ends -->
    <!-- ================== -->

    <div id="con-close-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">

    </div><!-- /.modal -->


    <!-- Footer Start -->
    <!--{template admin_v2/footer}-->
    <!-- Footer Ends -->



</section>
<!-- Main Content Ends -->


<!-- js placed at the end of the document so the pages load faster -->
<script src="<!--{eval echo register_static('js/jquery.js');}-->"></script>
<script src="<!--{eval echo register_static('js/bootstrap.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/pace.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/wow.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/jquery.nicescroll.js');}-->" type="text/javascript"></script>

<script src="<!--{eval echo register_static('js/jquery.app.js');}-->"></script>

<script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.init.js');}-->"></script>

<!-- Modal-Effect -->
<script src="<!--{eval echo register_static('assets/modal-effect/js/classie.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/modal-effect/js/modalEffects.js');}-->"></script>

<!-- infinitescroll -->
<script src="<!--{eval echo register_static('js/jquery.infinitescroll.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/lightbox.js');}-->"></script>

<script type="text/javascript">

    $(document).ready(function() {
        var sheet = getQuerystring('index');
        var op    = getQuerystring('op');
        var del_op= op == 'getDiaryAttachments' ? 'delDiaryAttachment' : 'delTopicAttachment';
        var alert_conf = {
            title: "确定删除?",
            text: "被删除附件不可以被恢复，请慎重操作!",
            type: "warning",
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            showCancelButton: true,
            closeOnConfirm: false
        };

        // 图片展示
        lightbox.option({
            'resizeDuration': 200,
            'wrapAround': true
        })

        $(document).on("click", ".delall", function () {

            $( "input[class=checkone]:checked" ).each(function() {
                var dataset = $(this).context.dataset;

                $.ajax(
                    {
                        url     :   "admin.php?ac=attachment&op="+del_op,
                        type    :   "POST",
                        data    :   {id : dataset.id, uid : dataset.uid, bodyId : dataset.bodyid, index : sheet},
                        success :   function(data)
                        {
                            if (data) {
                                $(".item[data-id="+ dataset.id +"]").hide();
                            }else{
                                swal("删除失败!", "删除附件时出现了问题！", "error");
                            }
                        }
                    });
            });
        });

        $(".panel-title").text(op == 'getDiaryAttachments' ? '点滴附件列表' : '圈子话题附件列表');
        $(".select-sheet a:eq("+sheet+")").attr('class', 'btn btn-inverse');
        $(document).on("click",".select-sheet a", function(){
            $(".select-sheet a").attr('class', 'btn btn-default');
            $(this).attr('class', 'btn btn-inverse');

            window.location = location.origin+'/admin.php?ac=attachment&op='+ op +'&index='+$(this).text();
        });

        // 删除附件
        $(document).on("click",".delete-attachment", function(){
            var atta = $(this).parent().parent().parent().data();
            var id    = atta.id;
            var uid   = atta.uid;
            var bodyId= atta.bodyid;

            swal(
                alert_conf,
                function(){
                    $.ajax(
                            {
                                url     :   "admin.php?ac=attachment&op="+del_op,
                                type    :   "POST",
                                data    :   {id : id, uid : uid, bodyId : bodyId, index : sheet},
                                success :   function(data)
                                {
                                    if (data) {
                                        swal("删除成功!", "该附件已被管理员删除！", "success");
                                        $(".item[data-id="+ id +"]").hide();
                                    }else{
                                        swal("删除失败!", "该附件删除出现了问题！", "error");
                                    }
                                }
                            });
                });
        });

        $('#attachments_list').infinitescroll({
            loading: {
                msgText: "",
                img: "../../static_v2/img/loading2.gif",
                finishedMsg: '没有新数据了哦...',
                selector: '.loading' //loading选择器
            },
            navSelector: "#nextpage", //导航的选择器，会被隐藏
            nextSelector: "#nextpage a",//包含下一页链接的选择器
            itemSelector: ".item",//你将要取回的选项(内容块)
            debug: false, //启用调试信息，若启用必须引入debug.js
            dataType: 'html',//格式要和itemSelector保持一致
            animate: false, //当有新数据加载进来的时候，页面是否有动画效果，默认没有
            extraScrollPx: 1300, //滚动条距离底部多少像素的时候开始加载，默认150
            errorCallback: function() { //加载完数据后的回调函数

            },
            path: function(index) { //获取下一页方法
                return "admin.php?ac=attachment&op="+op+"&page="+index+"&index="+sheet;
            },
        },
        function(newElements, data, url) { //回调函数

        });

        function getQuerystring(key, default_)
        {
            if (default_==null)
            {
                default_="";
            }
            var search = unescape(location.search);
            if (search == "")
            {
                return default_;
            }
            search = search.substr(1);
            var params = search.split("&");
            for (var i = 0; i < params.length; i++)
            {
                var pairs = params[i].split("=");
                if(pairs[0] == key)
                {
                    return pairs[1];
                }
            }


            return default_;
        }

    } );



</script>
</body>
</html>
